package com.vmj.natives.java.io;

import com.vmj.heap.VMObject;
import com.vmj.natives.NativeMethod;
import com.vmj.natives.Registry;
import com.vmj.rtda.Frame;
import com.vmj.rtda.LocalVars;

/**
 * Created by yangshoujun on 2017/9/23 下午6:48.
 */
public class FileOutputStream {

    public static final java.lang.String jlClass = "java/io/FileOutputStream";

    public static void init() {
        Registry.register(jlClass, "writeBytes", "([BIIZ)V", new NativeMethod() {
            public void execute(Frame frame) {
                LocalVars vars = frame.getLocalVars();
                VMObject data = vars.getRef(1);
                int offset = vars.getInt(2);
                int length = vars.getInt(3);

                byte[] bytes = (byte[])data.getData();
                String str = new String(bytes, offset, length);
                System.out.print(str);
            }
        });
    }
}
